﻿<div id="updateDialog" class="crudDialog">
    <form id="updateForm" method="post">
        <div class="form-group">
            <label for="name">权限名称</label>
            <input id="name" type="text" class="form-control" name="permissionName" maxlength="30"
                   th:value="${permission.permissionName}">
        </div>
        <input id="parenId" type="hidden" class="form-control" name="parentId" maxlength="30"
               th:value="${permission.parentId}">
        <input id="i" type="hidden" class="form-control" name="id" maxlength="30"
               th:value="${permission.id}">
        <input id="isParent" type="hidden" class="form-control" name="isParent" maxlength="30"
               th:value="${permission.isParent+1}">
        <div class="form-group">
            <label for="pvalue">权限值</label>
            <input id="pvalue" type="text" class="form-control" name="permissionValue" maxlength="30"
                   th:value="${permission.permissionValue}">
        </div>
        <div class="form-group">
            <label for="url">权限路径</label>
            <input id="url" type="text" class="form-control" name="permissionUrl" maxlength="30"
                   th:value="${permission.permissionUrl}">
        </div>
        <div class="form-group text-right dialog-buttons">
            <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
            <a class="waves-effect waves-button" href="javascript:;" onclick="updateDialog.close();">取消</a>
        </div>
    </form>
</div>
<script>

    function createSubmit() {
        $.ajax({
            type: 'post',
            url: 'update',
            data: $('#updateForm').serialize(),
            beforeSend: function () {
                if ($('#name').val() == '') {
                    $('#name').focus();
                    return false;
                }
            },
            success: function (result) {
                if (result.code != 0) {
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: result.errMsg,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                } else {
                    updateDialog.close();
                    $table.bootstrapTable('refresh');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.confirm({
                    theme: 'dark',
                    animation: 'rotateX',
                    closeAnimation: 'rotateX',
                    title: false,
                    content: textStatus,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button waves-light'
                        }
                    }
                });
            }
        });
    }
</script>